package com.bonc.rms.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.bonc.rms.service.PetGoodsService;
import com.bonc.rms.service.PetInfoService;

@RestController
@RequestMapping(value = "/petGoodsController")
public class PetGoodsController {
	@Autowired
	PetGoodsService petGoodsService;
	
	/*
	 * 查看主食信息
	 */
	@RequestMapping(value = "/getFoodsInfo")
	@ResponseBody
	public String getFoodsInfo() {
		
		List<Map<String, Object>> foodsInfo = petGoodsService.getFoodsInfo();
		
		return JSON.toJSONString(foodsInfo);
	}
	
	/*
	 * 查看单个主食的信息
	 */
	@RequestMapping(value = "/getSingleFoodInfo")
	@ResponseBody
	public String getSingleFoodInfo(@RequestParam(value = "foodId") Integer foodId) {
		
		List<Map<String, Object>> foodInfo = petGoodsService.getSingleFoodInfo(foodId);
		
		return JSON.toJSONString(foodInfo);
	}

	/*
	 * 修改主食信息
	 */
	@RequestMapping(value = "/updateFoodInfo")
	@ResponseBody
	public String updateFoodInfo(@RequestParam(value = "foodId") Integer foodId,
			@RequestParam(value = "foodName") String foodName,
			@RequestParam(value = "inventory") String inventory,
			@RequestParam(value = "pic") String pic,
			@RequestParam(value = "price") String price,
			@RequestParam(value = "quality") String quality,
			@RequestParam(value = "sold") String sold) {
		System.out.println(price);
		List<Map<String, Object>> foodInfo = petGoodsService.updateFoodInfo(foodId,foodName,inventory,pic,price,quality,sold);
		
		return JSON.toJSONString(foodInfo);
	}
	
	/*
	 * 删除主食信息
	 */
	@RequestMapping(value = "/deleteFoodInfo")
	@ResponseBody
	public String deleteFoodInfo(@RequestParam(value = "foodId") Integer foodId) {
		
		petGoodsService.deleteFoodInfo(foodId);
		
		Map<Object,Integer> map = new HashMap<>();
		map.put("status", 200);
		return JSON.toJSONString(map);
	}
	


}
